# -*- coding: utf-8 -*-
"""
File Name  windows_gui
Created on 2019-11-06

@author: jj

"""
import win32gui


def get_handles():
    handles_title = {}
    handles_dict = {}

    def get_all_hwnd(hwnd, mouse):
        if (win32gui.IsWindow(hwnd)
                and win32gui.IsWindowEnabled(hwnd)
                and win32gui.IsWindowVisible(hwnd)):
            handles_title.update({hwnd: win32gui.GetWindowText(hwnd)})

    win32gui.EnumWindows(get_all_hwnd, 0)

    for h, t in handles_title.items():
        if t:
            handles_dict[t] = h
    return handles_dict


if __name__ == '__main__':
    res = get_handles()
    print(res)
    if 'Morningstar Direct' in res:
        print(res['Morningstar Direct'])
